
//
//  BSTTests.swift
//  AlgorithmsTests
//
//  Created by Archer on 2018/8/20.
//  Copyright © 2018年 Archer. All rights reserved.
//

import XCTest
@testable import SwiftyDSA

class BSTTests: XCTestCase {
    
    func testInsert() {
        let tree = BinarySearchTree<Int>()
        for i in 1..<10 {
            tree.insert(i)
        }
        tree.travIn { print($0) }
        
    }
    
    func testRemove() {
        let tree = BinarySearchTree<Int>()
        for i in 1..<10 {
            tree.insert(i)
        }
        tree.travIn { print($0) }
        XCTAssertEqual(tree.count, 9)

        
        for i in 1..<10 {
            tree.remove(i)
            tree.travIn { print($0) }
            print("---------------------------------------------\n\n")
        }
        
        XCTAssertEqual(tree.count, 0)
        
//        print("---------------------------------------------\n")
//        tree.travIn { print($0) }

    }
    
    func testIR() {
        let tree = BinarySearchTree<Int>()
        tree.insert(36)
        tree.insert(27)
        tree.insert(6)
        tree.insert(58)
        tree.insert(53)
        tree.insert(64)
        tree.insert(40)
        tree.insert(46)
        tree.travIn { print($0) }

        
        tree.remove(36)
        print("\n---------------------------------------------\n")
        tree.travIn { print($0) }
        tree.remove(27)
        print("\n---------------------------------------------\n")
        tree.travIn { print($0) }
    }
}
